clear all
clc
addpath utils


%% RETROSPECTIVE UNDERSAMPLING NMSE and SSIM %%%

load SCR_DL_NMSE_SSIM_stats.mat
%This file contains NMSE and SSIM values for the following:
% GRAPPA at R=8 = grappa
% SENSE-DL at R=8 = esp
% SENSE-DL Ablation 1 at R=8 = esp1
% SENSE-DL Ablation 2 at R=8 = esp2
% SCR-DL at R=8 = prop

%mean and std 
A = [mean(nmse_grappa(:)) std(nmse_grappa(:)) mean(nmse_esp(:)) std(nmse_esp(:)) mean(nmse_prop(:)) std(nmse_prop(:));
     mean(ssim_grappa(:)) std(ssim_grappa(:)) mean(ssim_esp(:)) std(ssim_esp(:)) mean(ssim_prop(:)) std(ssim_prop(:));]
   
%%%%% cloud drop plots %%%%%%%%%%%%
addpath daviolinplot
data = [nmse_grappa(:) nmse_esp(:) nmse_prop(:)];

c =  [0.45, 0.80, 0.69;...
    0.98, 0.40, 0.35;...
    0.55, 0.60, 0.79;...
    0.90, 0.70, 0.30];

c = [ 0.9098, 0.4902, 0.1176];

figure, daviolinplot(data,'groups',[ones(2500,1)].','outsymbol','k+',...
    'xtlabels', {'GRAPPA', 'SENSE-DL', 'SCR-DL'},'color',c,'scatter',2,'jitter',1,...
    'box',1,'boxcolors','same','scattercolors','same',...
    'boxspacing',1.1);
ylabel('NMSE');,grid on


data = [ssim_grappa(:) ssim_esp(:) ssim_prop(:)];
c =  [0.45, 0.80, 0.69;...
    0.98, 0.40, 0.35;...
    0.55, 0.60, 0.79;...
    0.90, 0.70, 0.30];

c = [ 0.9098, 0.4902, 0.1176];

figure, daviolinplot(data,'groups',[ones(2500,1)].','outsymbol','k+',...
    'xtlabels', {'GRAPPA', 'SENSE-DL', 'SCR-DL'},'color',c,'scatter',2,'jitter',1,...
    'box',1,'boxcolors','same','scattercolors','same',...
    'boxspacing',1.1);
ylabel('SSIM');,grid on

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   
%%%%% one-way analysis of variance (ANOVA) %%%%%%%%%%%%
[p,tbl,stats]  = anova1([nmse_grappa(:) nmse_esp(:) nmse_prop(:)])
[results,means,~,gnames] = multcompare(stats,"CriticalValueType","bonferroni");
tbl = array2table(results)

%%%%% paired Student t-tests  %%%%%%%%%%%%
[results,means,~,gnames] = multcompare(stats,"CriticalValueType","bonferroni");


[p,tbl,stats]  = anova1([ssim_grappa(:) ssim_esp(:) ssim_prop(:)])
[results,means,~,gnames] = multcompare(stats,"CriticalValueType","bonferroni");
tbl = array2table(results)

%%%%% paired Student t-tests  %%%%%%%%%%%%
[results,means,~,gnames] = multcompare(stats,"CriticalValueType","bonferroni");

%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%% PROSPECTIVE UNDERSAMPLING LVEF and LV Mass %%%

load SCR_DL_LV_starts.mat
%This file contains LV measurement with the following:
%Row1: Sax SSFP Cine (Ground Truth)
%Row2: Sax SSFP Cine R8 with SCR-DL

%Column1: LVEF (%)
%Column2: LV EDV (ml)
%Column3: LV ESV (ml)
%Column4: LV ED Mass (g)



% Heart muscle territories per patient
territories = {'Subject',' ',' '};
nterritories = length(territories);

% Patient states during measurement
states = {'',''};
nstates = length(states);

% BA plot paramters
gnames = {territories, states}; % names of groups in data {dimension 1 and 2}
label = {'GRAPPA R=2','SCR-DL at R=8'}; % Names of data sets
corrinfo = {'n','SSE','r2','eq'}; % stats to display of correlation scatter plot
BAinfo = {};%{'RPC(%)','ks'}; % stats to display on Bland-ALtman plot
limits = 'auto'; % how to set the axes limits
if 1 % colors for the data sets may be set as:
	colors = 'br';      % character codes
else
	colors = [0 0 1;... % or RGB triplets
		      1 0 0];
end


% Generate figure with symbols for LV mass
tit = 'LV Mass'; % figure title
data1 = squeeze(subjects(1,4,:));
data2 = squeeze(subjects(2,4,:));

[cr, fig, statsStruct] = BlandAltman(data1, data2,label,tit,gnames,'corrInfo',corrinfo,'baInfo',BAinfo,'axesLimits',limits,'colors',colors, 'showFitCI',' on');


% Generate figure with symbols for LVEF
tit = 'LVEF'; % figure title
data1 = squeeze(subjects(1,1,:));
data2 = squeeze(subjects(2,1,:));

[cr, fig, statsStruct] = BlandAltman(data1, data2,label,tit,gnames,'corrInfo',corrinfo,'baInfo',BAinfo,'axesLimits',limits,'colors',colors, 'showFitCI',' on');


